package com.bawei.system.remote.factory;

import com.bawei.common.core.domain.R;

import com.bawei.es.domain.BulkDeleteDocs;
import com.bawei.es.domain.DocsQueryReq;
import com.bawei.es.domain.DocumentReq;
import com.bawei.es.domain.EsDocsQuery;
import com.bawei.system.remote.api.RemoteEsDocsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * Es文档服务  熔断处理
 *
 * @author bawei
 */
@Component
public class RemoteEsDocsFallbackFactory implements FallbackFactory<RemoteEsDocsService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteEsDocsFallbackFactory.class);

    @Override
    public RemoteEsDocsService create(Throwable cause) {
        log.info("文档操作失败:{}", cause.getMessage());
        return new RemoteEsDocsService() {

            @Override
            public R insertDocument(DocumentReq documentReq) {
                return R.fail("插入文档失败"+cause.getMessage());
            }

            @Override
            public R isExists(String indexName) {
                return  R.fail("索引查询失败"+cause.getMessage());
            }

            @Override
            public R deleteDocument(BulkDeleteDocs documentId) {
                return  R.fail("删除文档失败"+cause.getMessage());
            }

            @Override
            public R bulkDocument(DocumentReq documentReq) {
                return R.fail("批量添加文档失败"+cause.getMessage());
            }

            @Override
            public R updateDocument(DocumentReq documentReq) {
                return R.fail("修改文档失败"+cause.getMessage());
            }

            @Override
            public R<EsDocsQuery> docsQuery(DocsQueryReq docsQueryReq) {
                return R.fail("查询文档失败"+cause.getMessage());
            }
        };

    }


}
